package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.hfq.UploadBaseData;
import com.ucredit.babel.common.model.hfq.fraud.UploadFraudData;
import com.ucredit.babel.common.model.hfq.fraud.UploadFraudRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
/**
 * 欺诈类数据采集信息表
 *
 * @author guoqiang
 */

public class HfgUploadFraudParse extends ParseBase {
    Text key = new Text();
    Text value = new Text();

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        UploadFraudRecord obj = (UploadFraudRecord) model;
        UploadFraudData data = obj.getData();
        UploadBaseData baseData = data.getBaseData();
        StringBuilder sb = getBaseInfo(obj, successful);
        sb.append(baseData.getHttpTimestamp()).append(CRT001);
        sb.append(baseData.getUploadInfoOpportunity()).append(CRT001);
        sb.append(baseData.getVersion()).append(CRT001);
        sb.append(baseData.getIsAuthorized()).append(CRT001);
        sb.append(baseData.getOs()).append(CRT001);
        sb.append(data.getScreenRecording()).append(CRT001);
        sb.append(data.getScreenshot()).append(CRT001);
        sb.append(data.getOnCall()).append(CRT001);
        key.set(getKey());
        value.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, value);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_hfq_upload_fraud_inc";
    }

    @Override
    public String getType() {
        return RecordType.HFQ_UPLOAD_FRAUD_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "欺诈类数据采集信息表";
    }
}
